/**
 * 
 */
package edu.cmich.cps.cps240.partyprincesspalace.hw06;

import static org.junit.Assert.*;

import java.awt.Point;
import java.awt.Rectangle;
import java.util.Vector;

import org.junit.Test;

/**
 * @author roric1je
 *
 */
public class WorkspaceTest {
	
	private Chip getDefaultChip()
	{
		return new Chip(new Rectangle(0,0,10,10), new Vector<ChipPin>(), new Vector<ChipPin>(), "hai");
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Workspace#Workspace()}.
	 */
	@Test
	public void testWorkspace() {
		Workspace workspace = new Workspace();
		assertNotNull(workspace);
		
		assertNull(workspace.getChip());
		assertFalse(workspace.getDrag());
		
		
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Workspace#getDrag()}.
	 */
	@Test
	public void testGetDrag() {
		Workspace workspace = new Workspace();
		workspace.dragging(new Point(0,0));
		assertTrue(workspace.getDrag());
		workspace.endDrag(new Point(0,0));
		assertFalse(workspace.getDrag());
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Workspace#paint(java.awt.Graphics)}.
	 */
	@Test
	public void testPaintGraphics() {
		Workspace workspace = new Workspace();
		workspace.paint(workspace.getGraphics());
		//Just testing to make sure it doesn't crash
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Workspace#wasClicked(java.awt.Point)}.
	 */
	@Test
	public void testWasClicked() {
		Workspace workspace = new Workspace();
		Chip c = getDefaultChip();
		workspace.wasClicked(new Point (0,0));
		assertNull(workspace.hitChip(new Point (0,0)));
		workspace.setChip(c);
		workspace.wasClicked(new Point (0,0));
		assertNotNull(workspace.hitChip(new Point (0,0)));
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Workspace#hitChip(java.awt.Point)}.
	 */
	@Test
	public void testHitChip() {
		Workspace workspace = new Workspace();
		Chip c = getDefaultChip();
		workspace.setChip(c);
		Point p = new Point(10,10);
		workspace.wasClicked(p);
		assertNotNull(workspace.hitChip(p));
		p = new Point(25, 25);
		assertNull(workspace.hitChip(p));
		
		c.move(new Point(20,20));
		assertNotNull(workspace.hitChip(p));
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Workspace#startDragging(java.awt.Point)}.
	 */
	@Test
	public void testStartDragging() {
		Workspace workspace = new Workspace();
		Chip c = getDefaultChip();
		workspace.setChip(c);
		workspace.setWireTool(false);
		workspace.startDragging(new Point(0,0));
		workspace.setWireTool(true);
		workspace.startDragging(new Point(10,10));
		//StartDragging() function only means we are preparing to drag
		//dragging hasn't actually started yet
		assertFalse(workspace.getDrag());
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Workspace#dragging(java.awt.Point)}.
	 */
	@Test
	public void testDragging() {
		Workspace workspace = new Workspace();
		Chip c = getDefaultChip();
		workspace.setChip(c);
		workspace.wasClicked(new Point(0,0));
		assertNull(workspace.hitChip(new Point(15,15)));
		workspace.startDragging(new Point(5,5));
		workspace.dragging(new Point(10,10));
		assertNotNull(workspace.hitChip(new Point(15,15)));
		assertTrue(workspace.getDrag());
		
		workspace.setWireTool(true);
		workspace.startDragging(new Point(100,100));
		workspace.dragging(new Point(120, 120));
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Workspace#endDrag(java.awt.Point)}.
	 */
	@Test
	public void testEndDrag() {
		Workspace workspace = new Workspace();
		Chip c = getDefaultChip();
		workspace.setChip(c);
		workspace.setChip(c);
		workspace.wasClicked(new Point(0,0));
		workspace.startDragging(new Point(5,5));
		workspace.dragging(new Point(10,10));
		workspace.endDrag(new Point(15,15));
		assertFalse(workspace.getDrag());
		assertNotNull(workspace.hitChip(new Point(20,20)));
		
		workspace.setWireTool(true);
		workspace.startDragging(new Point(100,100));
		workspace.dragging(new Point(120, 120));
		workspace.endDrag(new Point(130,130));
		//collision detection for wires only applies to private methods
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Workspace#snapToGrid(java.awt.Point)}.
	 */
	@Test
	public void testSnapToGrid() {
		Point p = new Point(5,5);
		Point p2 = new Point(10,10);
		Point p3 = Workspace.snapToGrid(p);
		
		assertFalse(p.equals(p3));
		assertTrue(p2.equals(p3));
		
		
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Workspace#setChip(edu.cmich.cps.cps240.partyprincesspalace.hw06.Chip)}.
	 */
	@Test
	public void testSetChip() {
		Chip c = getDefaultChip();
		Workspace workspace = new Workspace();
		workspace.setChip(c);
		assertNotNull(workspace.getChip());
		assertTrue(workspace.getChip().equals(c));
		workspace.setChip(null);
		assertNull(workspace.getChip());
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Workspace#getChip()}.
	 */
	@Test
	public void testGetChip() {
		Chip c = getDefaultChip();
		Workspace workspace = new Workspace();
		workspace.setChip(c);
		assertNotNull(workspace.getChip());
		assertTrue(workspace.getChip().equals(c));
		workspace.setChip(null);
		assertNull(workspace.getChip());
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Workspace#setWireTool(boolean)}.
	 */
	@Test
	public void testSetWireTool() {
		Workspace workspace = new Workspace();
		workspace.setWireTool(false);
		workspace.setWireTool(true);
		//No corresponding "get" function.  setWireTool alters the
		//functionality of other methods, tested in their respective
		//functions
	}


}
